<template>
  <div>
    <jxf-titletip :title="title" @refreshPage="refreshFuc" :hasGoBack="true" @goBack="goBack"></jxf-titletip>
    <el-card class="jxf-table-card mt20">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
      </div>
      <jxf-table class="" :table="dataTable">
        <template slot="createTime" slot-scope="consoleInfo">
          <div>{{consoleInfo.row.createTime ? FormatDate.timeFormat(consoleInfo.row.createTime) : ""}}</div>
        </template>
        <template slot="terminalType" slot-scope="consoleInfo">
          <div v-if="consoleInfo.row.terminalType === 1">IOS</div>
          <div v-if="consoleInfo.row.terminalType === 2">安卓</div>
          <div v-if="consoleInfo.row.terminalType === 3">PC</div>
        </template>
      </jxf-table>
    </el-card>
    <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                    @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
  </div>
</template>

<script>
  import FormatDate from '@/assets/js/formatDate'
  export default {
    name: "Log",
    props: {
      dataInfo: {
        type: Object,
        default: () => {}
      }
    },
    data() {
      return {
        title: '登录日志',
        FormatDate: FormatDate,
        dataTable: {
          border:true,
          loading:false,
          hasSelect:false,
          tr: [
            {
              id: '1',
              label: '时间',
              show: 'template',
              prop: 'createTime'
            },
            {
              id: '2',
              label: '登录角色',
              prop: 'userName'
            },
            {
              id: '3',
              label: '地区',
              prop: 'area'
            },
            {
              id: '11',
              label: '登录方式',
              show: 'template',
              prop: 'terminalType'
            }
          ],
          data: []
        },
        pageTotal:0,
        pageSize:10,
        currentPage:1
      }
    },
    methods: {
      refreshFuc() {
        this.currentPage = 1;
        this.pageSize = 10;
        this.getData();
      },
      goBack() {
        this.$emit('goPreview')
      },
      getData() {
        this.dataTable.loading = true
        let data = {
          userId: this.dataInfo.userId,
          pageNum: this.currentPage,
          pageSize: this.pageSize
        }
        ajax.post(apis.user.getLog, data).then(result => {
          if(result.code == "10000000") {
            this.dataTable.data = result.data.dataList;
            this.pageTotal = result.data.total
          } else {
            this.$message.error(result.message)
          }
          this.dataTable.loading = false
        })
      },
      // 切换页面
      currentPageChange(pageNo) {
        this.currentPage = pageNo
        this.getData()
      },
      // 切换页面条数
      pageSizeChange(pageNo) {
        this.pageSize = pageNo
        this.getData()
      },
    },
    created() {
      this.getData()
    }
  }
</script>

<style lang="scss" scoped>

</style>
